package com.pd.backend.service.impl;

import com.pd.backend.entity.ScheduleJob;
import com.pd.backend.dao.ScheduleJobDao;
import com.pd.backend.service.ScheduleJobService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 定时任务(ScheduleJob)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:38
 */
@Service("scheduleJobService")
public class ScheduleJobServiceImpl implements ScheduleJobService {
    @Resource
    private ScheduleJobDao scheduleJobDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ScheduleJob queryById(String id) {
        return this.scheduleJobDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param scheduleJob 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<ScheduleJob> queryByPage(ScheduleJob scheduleJob, PageRequest pageRequest) {
        long total = this.scheduleJobDao.count(scheduleJob);
        return new PageImpl<>(this.scheduleJobDao.queryAllByLimit(scheduleJob, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param scheduleJob 实例对象
     * @return 实例对象
     */
    @Override
    public ScheduleJob insert(ScheduleJob scheduleJob) {
        this.scheduleJobDao.insert(scheduleJob);
        return scheduleJob;
    }

    /**
     * 修改数据
     *
     * @param scheduleJob 实例对象
     * @return 实例对象
     */
    @Override
    public ScheduleJob update(ScheduleJob scheduleJob) {
        this.scheduleJobDao.update(scheduleJob);
        return this.queryById(scheduleJob.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.scheduleJobDao.deleteById(id) > 0;
    }
}
